package drds.common.db.sql_mapping.dynamic_tag.token_handler;

import drds.common.db.sql_mapping.dynamic_tag.ognl.Ognl;
import drds.common.db.sql_mapping.dynamic_tag.tag_context.TagContext;

public class VariableReplacementTokenParser implements TokenHandler {
    private TagContext tagContext;

    public VariableReplacementTokenParser(TagContext tagContext) {
        this.tagContext = tagContext;
    }

    @Override
    public String handleToken(String content) {
        Object value = Ognl.getValue(tagContext.getTagContextMap(), content);
        String valueString = value == null ? "" : String.valueOf(value); // return "" instead of "null"
        return valueString;
    }
}
